package versi.vitro.oaiserviceprovider.test;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import versi.vitro.oaiserviceprovider.helper.GeneralHelper;
import versi.vitro.oaiserviceprovider.service.jena.api.JenaService;
import versi.vitro.oaiserviceprovider.service.jena.api.ModelBuilder;
import versi.vitro.oaiserviceprovider.service.transformer.api.TransformerService;
import versi.vitro.oaiserviceprovider.service.validation.api.ValidationService;

import com.hp.hpl.jena.rdf.model.ModelMaker;

public class BaseTestCase {

    protected ApplicationContext springContext;

    /** log4j instance. */
    private static final Logger LOGGER = Logger.getLogger(BaseTestCase.class);

    /**
     * RR: This method is not for actual use; remove it.
     * 
     * @param args
     *            command line parameters
     */
    public static void main(String args[]) {
	LOGGER.debug("1");
	try {
	    new BaseTestCase().initSpringFramework();
	} catch (Exception exception) {
	    String message = "Unable to intialise the Spring application context. ";
	    LOGGER.fatal(message, exception);
	    throw new RuntimeException(message, exception);
	}
    }

    @BeforeClass
    protected void initSpringFramework() throws Exception {
	String[] contextFiles = { "oai-test-applicationContext.xml", "oai-applicationContext.xml" };
	springContext = new ClassPathXmlApplicationContext(contextFiles);
    }

    @AfterClass
    protected void exitSpringFramework() throws Exception {
	springContext = null;
    }

    public GeneralHelper getGeneralHelper() {
	return (GeneralHelper) springContext.getBean("generalHelper");
    }

    public ModelMaker getModelMaker() {
	return (ModelMaker) springContext.getBean("jenaConnManager");
    }

    protected ModelBuilder getModelBuilder() {
	return (ModelBuilder) springContext.getBean("modelBuilder");
    }

    public JenaService getJenaService() {
	return (JenaService) springContext.getBean("jenaService");
    }

    public ValidationService getValidationService() {
	return (ValidationService) springContext.getBean("validationService");
    }

    public TransformerService getTransformerService() {
	return (TransformerService) springContext.getBean("transformerService");
    }
}
